<template>
    <el-card class="user-card" style="width: 50%;margin-right: 10px;">
        <template #header>
            <div class="card-header">
                <el-input v-model="searchName" placeholder="请输入姓名或身份证号" class="input-with-select">
                    <template #append>
                        <el-button @click="btn_loadbyname" :icon="Search" />
                    </template>
                </el-input>
            </div>
        </template>
        <el-table :data="userData" style="width: 100%;margin-left: auto;margin-right: auto;" :table-layout="tableLayout"
            :row-class-name="tableRowClassName" height="315">
            <el-table-column prop="id" label="序号" width="55%" />
            <el-table-column prop="name" label="姓名" />
            <el-table-column prop="sex" label="性别" />
            <el-table-column prop="age" label="年龄" />
            <el-table-column prop="telephone" label="联系电话" width="120%" />
            <el-table-column prop="idNum" label="身份证号" width="180%" />
            <el-table-column prop="address" label="家庭住址" width="180%" />
            <el-table-column label="操作" fixed="right" width="120%">
                <template #default="scope">
                    <el-button size="small" type="primary" @click="toReport(scope.$index, scope.row)">查看档案</el-button>
                </template>
            </el-table-column>

        </el-table>
        <el-config-provider :locale="locale">
            <el-pagination v-model:current-page="currentPage" :page-size="pageSize" v-model:total="total"
                :pager-count="10" background layout="prev, pager, next, jumper,total"
                @current-change="handleCurrentChange" style="width: max-content;margin-top: 15px" />

        </el-config-provider>
    </el-card>
</template>

<script setup>
import { storeToRefs } from "pinia";
import { useUserStore } from "../../../stores/user.js";
const userStore = useUserStore()
const { userData, currentPage, total, searchName } = storeToRefs(userStore)

const btn_loadbyname = () => {
    userStore.selectByNameOrIdNum()
}
const pageSize = ref(6)
const handleCurrentChange = () => {
    userStore.pageSize = pageSize.value
    userStore.getUsers()
}
handleCurrentChange()

import { useReportStore } from "../../../stores/report.js";
const reportStore = useReportStore()
const toReport = (index, row) => {
    reportStore.uId = row.id
    reportStore.selectReport(row.id)
}


import { ref, computed } from 'vue'
import { Search } from '@element-plus/icons-vue'
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
import en from 'element-plus/dist/locale/en.mjs'
//语言配置
const language = ref('zh-cn')
const locale = computed(() => (language.value === 'zh-cn' ? zhCn : en))
</script>

<style scoped>
.input-with-select .el-input-group__prepend {
    background-color: var(--el-fill-color-blank);
}
</style>